<html>
	<head>
		<title>nGrinder Script Result</title></title>
        <link type="text/css" rel="stylesheet" href="css/bootstrap.min.css">
        <link type="text/css" rel="stylesheet" href="css/codemirror.css">
        <link type="text/css" rel="stylesheet" href="css/eclipse.css">
        <style type="text/css">
        	pre {
        		overflow : hidden;
        	}
        	.save-btn {
        		margin : 6 0 6 12;
        	}
        </style>
        <script type="text/javascript" src="js/lib/jquery-1.11.3.min.js"></script>
        <script type="text/javascript" src="js/lib/bootstrap.min.js"></script>
        <script type="text/javascript" src="js/lib/codemirror.js"></script>
        <script type="text/javascript" src="js/lib/fullscreen.js"></script>
        <script type="text/javascript" src="js/lib/FileSaver.min.js"></script>
        <script type="text/javascript" src="js/common.js"></script>
        <script type="text/javascript" src="js/result.js"></script>
        <script type="text/javascript" src="js/lang/groovy.js"></script>
        <script type="text/javascript" src="js/lang/shell.js"></script>
	</head>
	<body>
		<div class="container">
			<div class="row">
				<div class="col-xs-12">
					<div class="alert alert-success" style="padding:12px;">
						<img src="/images/logo_ngrinder_a_header.png">
					</div>
					<div id="jsonArea">
						<div class="clearfix">
							<div class="pull-left">
								<h4>request.json</h4>
							</div>
							<div class="pull-right">
								<label id="saveJson" class="btn btn-danger btn-xs save-btn">Save as request.json</label>
							</div>
						</div>
						<textarea id="requestJsonText"></textarea>
					</div>
					<hr>
					<div id="groovyArea">
						<div class="clearfix">
							<div class="pull-left">
								<h4>TestRunner.groovy</h4>
							</div>
							<div class="pull-right">
								<label id="saveGroovy" class="btn btn-danger btn-xs save-btn">Save as TestRunner.groovy</label>
							</div>
						</div>
						<textarea id="groovyScriptText">
import static net.grinder.script.Grinder.grinder
import static org.hamcrest.Matchers.*
import static org.junit.Assert.*
import net.grinder.plugin.http.HTTPPluginControl
import net.grinder.plugin.http.HTTPRequest
import net.grinder.script.GTest
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.AfterThread
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread

import org.codehaus.groovy.reflection.ReflectionUtils;

import org.junit.Test
import org.junit.runner.RunWith

import org.ngrinder.recorder.RecorderUtils

import HTTPClient.CookieModule
import HTTPClient.HTTPResponse

/**
 * A simple example using the HTTPRequest that contain headers, cookies, body.
 * 
 * This script is automatically generated by nGrinder recorder.
 * 
 * @author Gisoo.Gwon
 */
@RunWith(GrinderRunner)
class TestRunner {
	public static GTest test
	public static HTTPRequest request
	public static def requestJson
	public Object cookies = []

	@BeforeProcess
	public static void beforeProcess() {
		HTTPPluginControl.getConnectionDefaults().timeout = 6000
		HTTPPluginControl.getConnectionDefaults().setFollowRedirects(true)
		test = new GTest(1, "Test1")
		request = new HTTPRequest()
		// Upload request.txt at resources folder
		// If use Groovy Manve porject, "ReflectionUtils.getCallingClass(0).getResourceAsStream("/request.json").getText("UTF-8")"
		String requestStr = new File("./resources/request.json").getText("UTF-8")
		requestJson = RecorderUtils.parseRequestToJson(requestStr)
	}

	@BeforeThread
	public void beforeThread() {
		test.record(this, "test")
		grinder.statistics.delayReports=true
		HTTPResponse result
		<nGrinderRecorderBeforeThreadRequestSend>
		cookies = CookieModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext())
	}

	@Test
	public void test() {
		cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
		HTTPResponse result
		<nGrinderRecorderTestRequestSend>
		cookies = CookieModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext())
	}

	@AfterThread
	public void afterThread() {
		cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
		HTTPResponse result
		<nGrinderRecorderAfterThreadRequestSend>
	}
}
</textarea>
					</div>
					<div id="jythonArea">
						<div class="clearfix">
							<div class="pull-left">
								<h4>TestRunner.py</h4>
							</div>
							<div class="pull-right">
								<label id="saveJython" class="btn btn-danger btn-xs save-btn">Save as TestRunner.py</label>
							</div>
						</div>
						<textarea id="jythonScriptText">
# -*- coding:utf-8 -*-

# A simple example using the HTTPRequest that contain headers, cookies, body.
# This script is automatically generated by nGrinder recorder.
#
# @author Gisoo.Gwon
import codecs
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest
from net.grinder.plugin.http import HTTPPluginControl
from org.ngrinder.recorder import RecorderUtils
from HTTPClient import CookieModule

control = HTTPPluginControl.getConnectionDefaults()
control.followRedirects = 1
# if you want to increase the timeout, please modify the following option.
control.timeout = 6000

test1 = Test(1, "Test1")
request = HTTPRequest()

class TestRunner:
	# initlialize a thread 
	def __init__(self):
		test1.record(TestRunner.__call__)
		grinder.statistics.delayReports=True
		requestStr = codecs.open("./resources/request.json", "r", "UTF-8").read()
		self.requestJson = RecorderUtils.parseRequestToJson(requestStr)
		<nGrinderRecorder__init__RequestSend>
		self.cookies = CookieModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext())
		pass

	# test method
	def __call__(self):
		for c in self.cookies: CookieModule.addCookie(c,HTTPPluginControl.getThreadHTTPClientContext())
		<nGrinderRecorder__call__RequestSend>
</textarea>
					</div>
				</div>
			</div>
		</div>
	</body>
</html>
